package org.asg.dis.repository;

import org.asg.dis.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserRepository extends JpaRepository<User, Long> {

//    @Query("SELECT u FROM User u WHERE u.phoneNumber = :phoneNumber")
    User findByPhoneNumber(@Param("phoneNumber") String phoneNumber);

    @Query("SELECT u FROM users u LEFT JOIN FETCH u.roles WHERE u.userId = :userId")
    User findByUserIdWithRoles(@Param("userId") Long userId);

//    @Query(value = "SELECT * FROM user_roles WHERE user_id = :userId", nativeQuery = true)
//    List<Map<String, Object>> findUserRolesByUserId(@Param("userId") Long userId);
    @Query(value = "SELECT role_id FROM user_roles WHERE user_id = :userId", nativeQuery = true)
    List<Object[]> findUserRolesByUserId(@Param("userId") Long userId);

}